import {require} from './require.js'
import Notify from '../@vant/notify/notify.js'
export default class personRequire{
  constructor(){

  }
  Login(phone,password){
   return require('/user/login','get',{
      data:{
        phone,
        password
      }
    }).then(res=>{
      console.log(res)
      const status = res.data.code === 200//登录成功
      const responseMsg = res.data.message
      if(status){
        wx.setStorageSync('token', res.data.obj.token)//设置全局状态
        wx.switchTab({url: '/pages/index/index'})//页面跳转
      }else{
        Notify({ type: 'danger', message: responseMsg })
      }
    })
  }
  getUserMsg(token){
    return require('/user/getUser','post',{
      header:{
        "token":token
      }
    }).then(res=>{
      //console.log(res)
      return res
    })
  }
  updateUserMsg(nickName,introduce,headName,token){
    return require('/user/updateHead','post',{
      header:{
        "token":token,
        "Content-Type":"application/x-www-form-urlencoded"
      },
      data:{
        headName,
        introduce,
        nickName
      }
    }).then(res=>{
      console.log(res)
      return res.data.code
    })
  }
  updateMsg(gender,vx,phone,token){
    return require('/user/updateData','post',{
      header:{
        "token":token,
        "Content-Type":"application/x-www-form-urlencoded"
      },
      data:{
        gender:gender === 'male'?0:1,
        vx,
        phone,
      }
    }).then(res=>{
      console.log(res)
      return res.data.code
    })
  }
  sendFeedback(title,content,token){
    return require('/feedback/addFeedback','post',{
      header:{
        "token":token,
        "Content-Type":"application/x-www-form-urlencoded"
      },
      data:{
        title,
        content
      }
    }).then(res=>{
      console.log(res)
      return res.data
    })
  }
  getFeedback(page,token){
    return require('/feedback/getFeedback','post',{
      header:{
        "token":token,
        "Content-Type":"application/x-www-form-urlencoded"
      },
      data:{
        page,
        limit:8
      }
    }).then(res=>{
      console.log(res)
      return res.data
    })
  }
  resign(phone,password,code){
    return require('/user/register','post',{
      header:{
        "Content-Type":"application/x-www-form-urlencoded"
      },
      data:{
        phone,
        password,
        code
      }
    })
    .then(res=>{
      console.log(res)
      const status = res.data.code === 200//注册成功
      const responseMsg = res.data.message
      if(status){
        Notify({ type: 'success', message: responseMsg })
      }else{
        Notify({ type: 'danger', message: responseMsg })
      }
    })
  } 

  sms(phone){
    return require('/user/sendMsg','post',{
      header:{
        "Content-Type":"application/x-www-form-urlencoded"
      },
      data:{
        phone
      }
    })
    .then(res=>{
      console.log(res)
      const status = res.data.code === 200//发送成功
      const responseMsg = res.data.message
      if(status){
        Notify({ type: 'success', message: responseMsg })
      }else{
        Notify({ type: 'danger', message: responseMsg })
        return 0
      }
    })
  }

  SMS(phone){
    return require('/user/sendMsg1','post',{
      header:{
        "Content-Type":"application/x-www-form-urlencoded"
      },
      data:{
        phone
      }
    })
    .then(res=>{
      console.log(res)
      const status = res.data.code === 200//发送成功
      const responseMsg = res.data.message
      if(status){
        Notify({ type: 'success', message: responseMsg })
      }else{
        Notify({ type: 'danger', message: responseMsg })
        return 0
      }
    })
  }
  forget(phone,password,code){
    return require('/user/forgetPassword','post',{
      header:{
        "Content-Type":"application/x-www-form-urlencoded"
      },
      data:{
        phone,
        password,
        code
      }
    })
    .then(res=>{
      console.log(res)
      const status = res.data.code === 200//修改成功
      const responseMsg = res.data.message
      if(status){
        Notify({ type: 'success', message: responseMsg })
      }else{
        Notify({ type: 'danger', message: responseMsg })
      }
    })
  } 
}